package bairui.international.weixin.portal.miniapp.controller.product.product;

import java.util.List;
import java.util.stream.Collectors;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.querydsl.QSort;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lianjing.sh.model.uml.model.status.State_UpDown;
import com.lianjing.sh.spring.web.controller.base.action.Action;
import com.lianjing.sh.spring.web.controller.enhance.output.FomatOutput;

import bairui.international.model.domain.jpa.TB_ProductRollImage;
import bairui.international.service.Service_ProductRollImage;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 *
 * 滚动图列表
 *
 * @generated
 * 
 * @see STest_C_Product_ListSlideImg_Get 测试
 *
 */
@Controller
public class C_Product_ListSlideImg_Get
 extends SC_Product_ListSlideImg_Get 
{
	
	@Autowired private Service_ProductRollImage service_ProductRollImage;
	
	/**
	 * Get请求
	 */
	@Action(Get.class)
	@GetMapping(Get.RequestMappingValue)
	public @FomatOutput @ResponseBody Object get(
		ModelMap map, HttpServletRequest request, 
		@PathVariable(name=Get.PathVariableName.Id) long id
	) throws Exception {
		List<TB_ProductRollImage> list = service_ProductRollImage.list(
				it->it.product.id.eq(id).and(it.state.eq(State_UpDown.Uped)), 
				it->new QSort(it.orderValue.desc())
			).getContent();
		return list
				.stream()
				.map(it->new Output(
						it.getId(), 
						new C_Product_ShowSlideImg_Get.Get.Operate() {
							@Override public Object getRollImgId() {
								return it.getId();
							}
						}.getUrl()
					))
				.collect(Collectors.toList());
	}
	
	@AllArgsConstructor
	private static class Output { 
		@Getter private Long id;
		@Getter private String url;
	}

}
